//
//  LYHHomeTableViewController.m
//  微考
//
//  Created by BrianLiu on 2017/5/11.
//  Copyright © 2017年 BrianLiu. All rights reserved.
//

#import "LYHHomeTableViewController.h"
#import "LYHTableViewHeaderView.h"
#import "LYHFastFoodModel.h"
#import "LYHFastFoodCell.h"

@interface LYHHomeTableViewController ()

@property (strong,nonatomic)NSArray *fastFoodGroups;

@end

@implementation LYHHomeTableViewController

//懒加载
-(NSArray *)fastFoodGroups
{
    if (_fastFoodGroups ==nil) {
        NSString *path = [[NSBundle mainBundle]pathForResource:@"fastfood.plist" ofType:nil];
        NSArray *fastFoodDict = [NSArray arrayWithContentsOfFile:path];
        NSMutableArray *temp = [NSMutableArray array];
        for (NSDictionary *dict in fastFoodDict) {
            LYHFastFoodModel *fastFoodModel = [LYHFastFoodModel fastFoodWith:dict];
            [temp addObject:fastFoodModel];
        }
        _fastFoodGroups = temp;
    }
    return _fastFoodGroups;
}


- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setUpNav];
    LYHTableViewHeaderView *showView = [LYHTableViewHeaderView showView];
    showView.imageNames = @[@"wow1",@"wow2",@"wow3",@"wow4",@"wow5",@"wow6",@"wow7",@"wow8",@"wow9",@"wow10",@"wow11",@"wow12"];
//    [self.tableView addSubview:showView];
    self.tableView.tableHeaderView = showView;
    
}

// 设置导航条
-(void)setUpNav{
    self.navigationItem.title = @"首页";
}

#pragma mark - Table view data source

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    return self.fastFoodGroups.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    //设置标识
    static NSString * ID = @"fastFood";
    //去缓存池找
    LYHFastFoodCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    //判断
    if (cell == nil) {
        cell = [[LYHFastFoodCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:ID];
    }
    cell.fastFoodModel = self.fastFoodGroups[indexPath.row];
    return cell;

    
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 66;
}

@end
